package com.xiaoming.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {

    private static Calculator metricsTask = new Calculator();


    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String methodName = invocation.getMethodName();
        Long startTime = System.currentTimeMillis();
        Result invoke = invoker.invoke(invocation);
        Meterics meterics = new Meterics();
        meterics.setStarTime(startTime);
        meterics.setDuration(System.currentTimeMillis() - startTime);
        metricsTask.put(methodName, meterics);
        return invoke;
    }
}
